package com.leoandroid.tool.toolsbox.utils

import android.app.Activity
import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
import android.view.LayoutInflater
import android.widget.TextView
import com.leoandroid.tool.toolsbox.largeread.R

class PremissDialog : Dialog {
    private var onDialogClickListener: OnDialogClickListener? = null
    private var isFinish = false
    private var mContext:Context? = null
    constructor(context: Context) : super(context){
        this.mContext = context
        initView()
    }
    constructor(context: Context, themeResId: Int) : super(context, themeResId){
        this.mContext = context
        initView()
    }
    constructor(
        context: Context,
        cancelable: Boolean,
        cancelListener: DialogInterface.OnCancelListener?
    ) : super(context, cancelable, cancelListener){
        this.mContext = context
        initView()
    }

      fun initView() {
          val inflate = LayoutInflater.from(mContext).inflate(R.layout.premiss_dialog_layout, null)
          setContentView(inflate)
          setOnDismissListener {
              if (isFinish) {
                  (mContext as Activity).finish()
              }
          }
          setCanceledOnTouchOutside(false)
          findViewById<TextView>(R.id.protocol_content).text = "为了您浏览咨询及缓存文件，我们会申请存储权限"
          findViewById<TextView>(R.id.protocol_agree).setOnClickListener {
              onDialogClickListener?.onAgree()
              dismiss()
          }
          findViewById<TextView>(R.id.protocol_cancel).setOnClickListener {
              onDialogClickListener?.onCancel()
              dismiss()
          }
      }


    fun setOnDialogClickListener(onDialogClickListener: OnDialogClickListener){
        this.onDialogClickListener = onDialogClickListener
    }


    interface OnDialogClickListener{
        fun onAgree()
        fun onCancel()
    }

}